package com.yby.mall.product.controller;

import java.util.List;

import com.yby.mall.product.vo.CategoryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.yby.mall.product.entity.CategoryEntity;
import com.yby.mall.product.service.CategoryService;
import com.yby.common.utils.R;



/**
 * 商品三级分类
 *
 * @author yangbingying
 * @email 2771355658@qq.com
 * @date 2021-07-09 20:49:20
 */
@Api(value = "", tags = "商品三级分类")
@RestController
@RequestMapping("/product/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    /**
     * 列表
     */
    @ApiOperation("获取商品三级分类列表树形展示(方法一)")
    @GetMapping("/list/tree")
    public R list(){
        return categoryService.getList();
    }

    /**
     * 列表
     */
    @ApiOperation("获取商品三级分类列表树形展示(方法二)")
    @GetMapping("/list/tree1")
    public R list1(){
        return categoryService.getList1();
    }


    /**
     * 信息
     */
    @GetMapping("/info/{catId}")
    public R info(@PathVariable("catId") Long catId){
		CategoryEntity category = categoryService.getById(catId);
        return R.ok().put("data", category);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody CategoryVo categoryVo){
        return categoryService.save(categoryVo);
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public R update(@RequestBody CategoryVo categoryVo){
        return categoryService.update(categoryVo);
    }

    @PostMapping("/update/sort")
    public R updateSort(@RequestBody List<CategoryVo> list){
        return categoryService.updateSort(list);
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    public R delete(@RequestBody List<Long> catIds){
		categoryService.removeByIds(catIds);
        return R.ok();
    }

}
